home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_11_12 / winroth / exc_sig.h < prev    next >
Encoding:
C/C++ Source or Header  |  1993-10-20  |  4.2 KB  |  136 lines

  1. /*
  2. ** Exception Library -- General exception handling for ANSI C programs
  3. ** 
  4. ** Copyright (C) 1992 Computational Vision and Active Perception Lab. (CVAP),
  5. **                    Royal Institute of Technology, Stockholm.
  6. **
  7. ** This library is free software; you can redistribute it and/or
  8. ** modify it under the terms of the GNU Library General Public
  9. ** License as published by the Free Software Foundation; either
  10. ** version 2 of the License, or (at your option) any later version.
  11. ** 
  12. ** This library is distributed in the hope that it will be useful,
  13. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  15. ** Library General Public License for more details.
  16. ** 
  17. ** You should have received a copy of the GNU Library General Public
  18. ** License along with this library (see COPYING-LIB); if not, write to 
  19. ** the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, 
  20. ** USA.
  21. ** 
  22. **                            Written by
  23. **                                 
  24. **                  Harald Winroth, Matti Rendahl
  25. **      Computational Vision and Active Perception Laboratory
  26. **                  Royal Institute of Technology
  27. **                        S-100 44 Stockholm
  28. **                              Sweden
  29. **                                 
  30. ** Report bugs to candela-bug@bion.kth.se, and direct all inquiries to 
  31. ** candela@bion.kth.se.
  32. **
  33. */
  34.  
  35. #ifndef _exception_exc_sig_h
  36. #define _exception_exc_sig_h
  37.  
  38. #include <signal.h>
  39.  
  40. #if defined(SVR4) || defined(SYSV) || defined(_SYSV_)
  41. #include <siginfo.h>
  42. #include <ucontext.h>
  43. #endif
  44.  
  45. #include <exception/exception.h>
  46. #include <exception/exc-sig-macros.h>
  47.  
  48. /*
  49.  * The _EXC_SIG_HANDLER_ARGS definition should match the system's declaration
  50.  * of signal handler arguments. The SIG_ARG parameter is the name of the 
  51.  * formal parameter that should contain the signal number (it will be used in 
  52.  * the body of the handler).
  53.  */
  54.  
  55. #if defined(__sun__) /* SunOS 4 and 5 */
  56. #define _EXC_SIG_HANDLER_ARGS(SIG_ARG_NAME)                      \
  57.     int SIG_ARG_NAME
  58. #elif defined(sgi) /* Silicon Graphics IRIX */
  59. #define _EXC_SIG_HANDLER_ARGS(SIG_ARG_NAME)                      \
  60.     int SIG_ARG_NAME
  61. #elif defined(SVR4) || defined(SVR4) || defined(SYSV) || defined(_SYSV_)
  62. #define _EXC_SIG_HANDLER_ARGS(SIG_ARG_NAME)                      \
  63.     int SIG_ARG_NAME, siginfo_t *infop, ucontext_t *ucp
  64. #else
  65. #define _EXC_SIG_HANDLER_ARGS(SIG_ARG_NAME)                      \
  66.     int SIG_ARG_NAME, ...
  67. #endif
  68.  
  69. typedef void (*excSigHandler) (_EXC_SIG_HANDLER_ARGS (sig));
  70.  
  71. typedef struct
  72. {
  73.     char *name;
  74.     int number;
  75.  
  76. } excSig;
  77.  
  78. /*
  79.  * Declare excSigDomain
  80.  */
  81.  
  82. #include <exception/exc-sig-list.h>
  83.  
  84. /*
  85.  * exc_sig is the domain of all signal exceptions, its type is excSigDomain. 
  86.  * The type of the individual exceptions is excSig. Note: The location (index)
  87.  * of the signals in the exc_sig struct will NOT in general be the same as the
  88.  * signal number.
  89.  */
  90.  
  91. extern excSigDomain exc_sig;
  92. extern int exc_sig_type;
  93.  
  94. /*
  95.  * These functions returns information about an excSig exception.
  96.  */
  97.  
  98. extern char *exc_sig_name (excSig sig);
  99. extern int exc_sig_number (excSig sig);
  100.  
  101. /*
  102.  * exc_sig_exception_handler() is an exception handler (NOT a signal
  103.  * handler) which is installed automaically by exc_signal(). It prints 
  104.  * an error messages for excSig exceptions that are not caught.
  105.  */
  106.  
  107. extern int exc_sig_exception_handler (void *e, void *e_type, void *h_data);
  108.  
  109. /*
  110.  * exc_sig_handler is a signal handler that translates signals to exceptions.
  111.  * It is installed by exc_signal().
  112.  */
  113.  
  114. extern void exc_sig_handler (_EXC_SIG_HANDLER_ARGS (sig));
  115.  
  116. /*
  117.  * exc_signal() installs exc_sig_handler() for a specific signal, just as
  118.  * signal(2) does.
  119.  */
  120.  
  121. extern excSigHandler exc_signal (int sig);
  122.  
  123. /*
  124.  * exc_signals() works like exc_signal() but installs exc_sig_handler() for
  125.  * multiple signals. This list is specified by a mask (int) in BSD and by
  126.  * an sigset_t* in SYSV. The previous handles are not returned.
  127.  */
  128.  
  129. #if defined(SVR4) || defined(SYSV) || defined(_SYSV_)
  130. extern void exc_signals (sigset_t *set);
  131. #else
  132. extern void exc_signals (int mask);
  133. #endif
  134.  
  135. #endif /* !_exception_exc_sig_h */
  136.